<template>
	<view>
		<u-search placeholder="请输入" v-model="keyword" actionText='搜索' @change='onchange'></u-search>
		
		<!-- 热门搜索 -->
		<template v-if='showMode===1'>
			<MyTags title="热门搜索" :list="hotKeywordList" @chickTag="onClickTag"></MyTags>
		</template>
		<!-- 搜索列表 -->
		<template v-else>
			<view>
				<u-cell-group>
					<u-cell v-for='(item,index) in searchlist' :key='index' :title="item" @click="onClickto(item,index)"></u-cell>
				</u-cell-group>
			</view>
		</template>
	</view>



</template>

<script>
import keyboard from 'uview-ui/libs/config/props/keyboard';
	export default {
		onShow(){
			console.log(123);
			this.$api({
				url:'/lp/searchlist',
				successCB:res=>{
					console.log(res.data);
					this.hotKeywordList = res.data.map((it)=>{
						return {text:it}
					})
				}
			})
		},
		data() {
			return {
				keyword: '',
				searchlist: [],
				showMode: 1,
				hotKeywordList:[]
			}
		},
		methods: {
			
			onchange(val) {
				this.showMode = 2
				// console.log(1);
				this.$api({
					url: '/lp/searchlist',
					data:{
						keyword:this.keyword
					},
					successCB: res => {
						console.log(res);
						this.searchlist = res.data
					console.log(this.searchlist);
						if (this.keyword == '') {
							this.showMode = false
						}
					}


				})
			},
			//热门搜索点击事件
			onClickTag(text){
				console.log(text);
				uni.navigateTo({
					url:`/pages/search/searchGood/searchGood?name=${text}`
				})
			},
			//搜索列表点击事件
			onClickto(it,i){
				uni.navigateTo({
					url:`/pages/search/searchGood/searchGood?name=${it}`
				})
			}
		}
	}

</script>

<style>


</style>